﻿using System;
using System.Management.Automation;

namespace ExpressionAutomation
{
    [Cmdlet("Combine", "Media")]
    public class CombineMediaCmdlet : PSCmdlet
    {
        [Parameter(Position = 1, Mandatory = true)]
        public string MoviePath { get; set; }

        [Parameter]
        public string IntroPath { get; set; }

        [Parameter]
        public string OutroPath { get; set; }

        [Parameter(Position = 2, Mandatory = true)]
        public string DestinationPath { get; set; }

        protected override void BeginProcessing()
        {
            Console.WriteLine("Beginning Processing");
            base.BeginProcessing();
        }

        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            var combiner = new MediaItemCombiner();
            combiner.OnCombinerProgress += new EventHandler<Microsoft.Expression.Encoder.EncodeProgressEventArgs>(combiner_OnCombinerProgress);
            combiner.Combine(MoviePath, IntroPath, OutroPath, DestinationPath);
        }

        void combiner_OnCombinerProgress(object sender, Microsoft.Expression.Encoder.EncodeProgressEventArgs e)
        {
            Console.WriteLine("Progress: " + e.Progress);
        }

        protected override void EndProcessing()
        {
            Console.WriteLine("Processing completed.");
            base.EndProcessing();
        }
    }
}
